package com.ms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ms.domain.entity.Music;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MusicMapper extends BaseMapper<Music> {

    // 分页查询音乐（带关联信息）
    @Select("SELECT m.*, u.username AS creator_name, g.name AS genre_name, a.title AS album_title " +
            "FROM music m " +
            "LEFT JOIN user u ON m.creator_id = u.id " +
            "LEFT JOIN genre g ON m.genre_id = g.id " +
            "LEFT JOIN album a ON m.album_id = a.id " +
            "WHERE m.status = 'APPROVED' " +
            "ORDER BY m.create_time DESC")
    List<Music> selectMusicWithDetails();

    // 按曲风查询音乐
    @Select("SELECT * FROM music WHERE genre_id = #{genreId} AND status = 'APPROVED'")
    List<Music> selectByGenreId(@Param("genreId") Integer genreId);

    // 查询用户上传的音乐
    @Select("SELECT * FROM music WHERE creator_id = #{userId}")
    List<Music> selectByCreatorId(@Param("userId") Integer userId);
}
